/**
 * 
 */
package org.acsis.covoiturage.frontend.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.acsis.covoiturage.frontend.application.SVC;
import org.acsis.covoiturage.frontend.forms.*;
import org.acsis.covoiturage.services.IClientServices;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 * @author Abdellah
 *
 */
public class ForgotAction extends Action {

	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		IClientServices clientServices = SVC.create(IClientServices.class);
		String id= ((ForgotForm)form).getForgotIdentifiant();
		boolean OK = clientServices.passwordForgotten(id);
		if (OK) {
			return mapping.findForward("success");
		} else {
			ActionErrors errors = new ActionErrors();
			errors.add("forgotEchec",new ActionMessage("erreur.forgotEchec"));
			saveErrors(request, errors);
			return mapping.findForward("failed");

		}
	}

	
}
